<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/common/back-common.jsp"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp"%>
<%@ include file="/WEB-INF/pages/common/jquery2.1.4.jsp"%>
<script type='text/javascript' src="<ls:templateResource item='/resources/common/js/jquery.validate.js'/>" /></script>
<link rel="stylesheet" type="text/css" media="screen" href="${contextPath}/resources/common/css/errorform.css" />
<%@ include file="/WEB-INF/pages/common/back-dialog.jsp"%>
        <script language="javascript">
    $.validator.setDefaults({
    });

    $(document).ready(function() {
    jQuery("#updatePwd").validate({
        rules: {
            oldPassword: {
                required: true
            },
            password: {
		        required: true
		    },
		    password2:{
		    	equalTo: "#password"
		    }
        },
        messages: {
          	 oldPassword: {
                required: '必填'
            },
            password: {
                required: '必填'
            },
            password2:{
		    	 equalTo: "密码必须要一致"
		    }
        }
    });
     	 //binding Submit
     	 $("#Submit").click(function(){
     	 if($("#updatePwd").valid()){
     	 var formData = $("#updatePwd").serialize();
     	   $.ajax({
            type: 'post', // 提交方式 get/post
            url:  "${contextPath}/admin/adminUser/updatePwd", // 需要提交的 url
            data: formData,
            dataType : 'json', 
            error: function(jqXHR, textStatus, errorThrown) {
		 		 alert("保存失败" + textStatus);
			},
            success: function(data) { // data 保存提交后返回的数据，一般为 json 数据
                // 此处可对 data 作相关处理
                if("OK" == data){
                  closeDialog();
                  layer.msg("密码修改成功");
                }else if("NOCHANGE" == data){
                	layer.msg("密码不能跟原密码一致");
                }else if("DISMATCH" == data){
                	layer.msg("请输入正确的原密码");
                }else if("TOSIMPLE" == data){
                    layer.msg("密码必须由大小写字母+数字+特殊符号组合，长度大于8位。");
                }else{
                	layer.msg("修改密码失败");
                }
              
            }
        });
        return false; // 阻止表单自动提交事件
		};
		});
});

	function closeDialog(){
		var index = parent.layer.getFrameIndex("changeAdminPwd"); //先得到当前iframe层的索引
		window.parent.refreshMyProfile();
		parent.layer.close(index); //再执行关闭 
		if(parent.sendData){
			parent.sendData();//异步
		}else{
			parent.location.reload();
		}
		
	}
	
</script>
</head>
<body>
<div align="center">      
      <form:form   action="${contextPath}/admin/adminUser/updatePwd" id="updatePwd" method="post">
        <table align="center" class="${tableclass}" id="col1" style="width: 450px">
                <thead>
                    <tr class="sortable">
                        <th colspan="2">
                            <div align="center"> 修改成员 ${adminUser.name } 权限</div>
                            <input type="hidden" name="id" value="${adminUser.id }" >
                        </th>
                    </tr>
                </thead>
		<tbody>
       	 <tr>
            <td height="27" align="center" class="forumRow"><div align="right">原密码 <font color="ff0000">*</font></div></td>
            <td align="center" class="forumRow"><input type="password" name="oldPassword"  id="oldPassword"  value="" autocomplete="off"></td>
          </tr>
        	<tr>
            <td height="27" align="center" class="forumRow"><div align="right">新密码 <font color="ff0000">*</font></div></td>
            <td align="center" class="forumRow"><input type="password" name="password"  id="password"  value="" autocomplete="off"></td>
          </tr>
       	 <tr>
            <td height="27" align="center" class="forumRow"><div align="right">确认密码 <font color="ff0000">*</font></div></td>
            <td align="center" class="forumRow"><input type="password" name="password2"  id="password2"  value="" autocomplete="off"></td>
          </tr>         
          <tr >
            <td height="42" colspan="2" class="forumRow">
                  <div align="center">
                   <input type="button" name="Submit" id="Submit" value="提交">
                   <input type="reset" name="cancel" value="重置">
                   <input type="button" value="关闭"
                       onclick="javascript:closeDialog()" />
                   </div>
            </td>
          </tr>
        </tbody>
        </table>
      </form:form>
</div>
</body>
</html>

